package com.douyinkan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.douyinkan.dto.ContentDTO;
import com.douyinkan.entity.Favorite;
import com.douyinkan.entity.Rating;
import com.douyinkan.mapper.FavoriteRepository;
import com.douyinkan.mapper.RatingRepository;
import com.douyinkan.service.ContentService;
import com.douyinkan.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private FavoriteRepository favoriteRepository;

    @Autowired
    private RatingRepository ratingRepository;

    @Autowired
    private ContentService contentService;

    @Override
    public List<ContentDTO> getFavoriteContents() {
        List<Favorite> favorites = favoriteRepository.selectList(null);
        return favorites.stream()
                .map(fav -> contentService.getContentById(fav.getContentId()))
                .collect(Collectors.toList());
    }

    @Override
    public List<ContentDTO> getRatedContents() {
        List<Rating> ratings = ratingRepository.selectList(null);
        return ratings.stream()
                .map(rating -> contentService.getContentById(rating.getContentId()))
                .collect(Collectors.toList());
    }

    @Override
    public List<ContentDTO> getViewHistory() {
        // 由于 ViewHistoryRepository 还没有完全实现相关查询方法，
        // 暂时返回空列表，后续可以完善
        return List.of();
    }
}